package com.javaweb.controller;

/**
 * @desc:
 * @author: Ping
 * @date: 2024/10/22 23:01
 */

import com.javaweb.controller.common.ResponseResult;
import com.javaweb.model.Article;
import com.javaweb.service.ArticleService;
import com.javaweb.service.dto.ArticleConditionDto;
import com.javaweb.service.dto.ArticleDto;
import com.javaweb.service.dto.ArticleUpdateDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * todo: 文章管理模块
 */
@RestController
@RequestMapping("/blog-api/v0.1/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping("/list")
    public ResponseResult<List<Article>> getList(@RequestBody ArticleConditionDto articleCond){
        return ResponseResult.ok(articleService.queryByArticleCondition(articleCond));
    }

    @PostMapping("/add")
    public ResponseResult add(@RequestBody Article articleCond){
        return ResponseResult.ok(articleService.addArticle(articleCond),"添加成功");
    }

    @PostMapping("/update")
    public ResponseResult update(@RequestBody ArticleUpdateDto article){
        return ResponseResult.ok(articleService.updateArticle(article),"修改成功");
    }

    @GetMapping("/{id}/publish")
    public ResponseResult publish(@PathVariable String id){
        return ResponseResult.ok(articleService.publishArticle("1",id),"发布成功");
    }


}
